/*
 * @desc: 
 * @author: mao
 * @version: 1.0
 * @Date: 2023-07-24 14:36:06
 */
import { ref } from 'vue';
import { defineStore } from "pinia";

export interface FileItem {
    size: number;
    percent: number;
    name?: string;
    state?: string | number;    // 处理状态
    status?: string | number; // 上传状态
    url?: string;
    type?: string;
    time?: number;
    subscription?: any;
    instance?: any;
    pause?: boolean;
    is_pause?: boolean;
    is_uploaded: number;
    id: string;
    directory_id: string;
    key?: string;
    hash?: string;
    userId?: string;
}

export const useFileInfoStore = defineStore('cutList', {
	state: () => {
        return {
            uploadFileList: ref<FileItem[]>([]),
            directory_id: ref<string>('0'),
            localCutList: ref<any>([]),
            processStatus: ref<any>()
        }
    },
    actions: {
        setUploadFileList (data: any) {
            this.uploadFileList = data;
            const obj = {
                uploadFileList: data,
                directory_id: this.directory_id
            }
            localStorage.setItem('localFileList', JSON.stringify(obj));
        },
        setDirectoryId (data: string = '0') {
            this.directory_id = data;

            const obj = {
                directory_id: data,
                localCutList: this.localCutList
            };
            localStorage.setItem('cutList', JSON.stringify(obj));
        },
        setLocalCutList (data: any) {
            this.localCutList = data;

            const obj = {
                directory_id: this.directory_id,
                localCutList: data
            };
            localStorage.setItem('cutList', JSON.stringify(obj));
        },
        setProcessStatus (data: any) {
            this.processStatus = data;
        }
    }
});
